package lesson3.slides.io;

import java.io.*;

public class PrintWriterExample {

    public static void main(String[] args) {
        // Create the Buffered Reader
        BufferedReader input = new BufferedReader(
                new InputStreamReader(System.in));
        try {
            // Create the writer (buffered!)
            PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("dialog.text")));
            pw.println("----------- Starting");
            int lineNum = 1;
            while (true) {
                System.out.print("Enter a line ('end' terminates):");
                String s = input.readLine();
                if (s.equals("end")) {
                    break;
                }
                System.out.println("You said -- " + s);
                pw.print(lineNum++);
                pw.println(")  " + s);
            }
            System.out.println("bye");
            pw.println("----------- Done");
            pw.close();
        } catch (Exception e) {
            System.err.println(e);
        }
    }
}
